/**
 * class name: valid$,
 * copyright: maximus zhang,
 * License: MIT-LICENSE,
 * contact: maximus.zhang@gmail.com,
 * required-js: http://hcjs.googlecode.com/svn/trunk/hc.js,
 * update: http://hcjs.googlecode.com/svn/trunk/valid.js
 *
 */
/*
 * <input valid="type:str;minlen:2;maxlen:9;hint:true;live:true;" />
 * --
 */
function valid$(){/* {json} */
    var A = arguments,
        _ = this;
    _ = ext$( _, ext$( { rgx : {
        varname : /^[a-z][a-z0-9]*(\.)?[a-z0-9]+$/i,
        code : /^[a-zA-Z][A-Za-z0-9]+$/,
        pwd : /^[A-Za-z0-9].+$/,
        num : /^\d+$/,
        str : /.*/
    }, rule : {} }, A[0] ) );

    _.uitype = 'valid$';

    _.tip$ = function(){
    };

    _.check$ = function(){
    };

    _.exec$ = function(o,r){
        if ( !o || !o.nodeName || !o.name || o.name=='' ) {
            return null;
        }

        if ( !r || typeof r!='object' ) {/* if no r given or r is not json*/
            var r = attr$(o,'valid');
            if ( r ) {
                r = r.jsonCSS$();
            }
        }

        if ( !p$(r,'type') || !p$(_.reg,r.type) ) {
            return undefined;
        }

        var minlen = p$(r,'minlen') ? r.minlen : p$(r,'len') ? (r.len.split('-')[0]*1||0) : 0,
            maxlen = p$(r,'maxlen') ? r.maxlen : p$(r,'len') ? (r.len.split('-')[1]*1||254) : 254;
        switch ( o.nodeName ) {
            case 'INPUT':
                switch (o.type) {
                    case 'text':
                        if (r.live) {
                            bind$( o, 'blur', function(){
                                _.check$( _.rule[o.name], o.value );
                                } );
                        }
                        break;
                }
                break;
            case 'TEXTAREA':
                ;
                break;
            case 'SELECT':
                ;
                break;
        }
    };

    _.init$ = function(){
        if ( typeof _.rule=='string' ) {
            var el = $(_.rule);
        } else if ( typeof _.rule=='object' ) {
            for ( var x in _.rule ) {
            }
        }
    };
}
function validForm$(fo){
    if ( !fo || fo.nodeName!='FORM' ) {
        return fo;
    }

    for ( var x = 0, L = fo.length; x<L; x++ ) {
        if ( !fo[x].disabled && fo[x].name && fo[x].name!='' ) {
            var r = attr$(fo[x], 'valid'),
                v = fo[x];

            if ( !r ) {
                continue;
            }

            r = r.jsonCSS$();

            switch ( v.nodeName ) {
                case 'INPUT':
                    switch ( v.type ) {
                        case 'hidden':
                            break;
                        case 'text':
                        case 'password':
                            switch ( r.type ) {
                                case '':
                                break;
                            }
                            break;
                    }
                    break;
                case 'TEXTAREA':
                    break;
                case 'SELECT':
                    break;
                default:
                    break;
            }
        }
    }

return true;
}